﻿using System;
using CfgMusic;
using CMPart;
using com.m3sdk.common;
using CSUtils;
using DG.Tweening;
using G02.PlayerData;
using GlobalTripleJump;
using m3sdk;
using U3dGame;
using U3dUtils;
using UnityEngine;
using UnityEngine.Serialization;

namespace TripleJump {
    public class TripleJump_FristRoleFly : CRole {
        const string _tag = "TripleJump_FristRoleFly";
        public CPara para = new CPara();
        CJetpack jetpack = new CJetpack();
        CTrailingGround trailingGround = new CTrailingGround();
        CMaxDistanceTips maxDistanceTips;
        CRolePosRing rolePosRing;
        CCurrentDistanceTips currDistanceTips;
        CRoleAi roleAi = new CRoleAi();
        public Part_021_BloodStrip bloodStrip = new Part_021_BloodStrip();
        Transform subRoot => skinTf;

        public override void Init(Transform root, MRoleCfgInfo roleCfg, Transform skinTf) {
            base.Init(root, roleCfg, skinTf);
            jetpack.Init(root);
            trailingGround.Init();
            totalHigh = para.maxHighLimit + CCylinderTerrain.CPara.radius;
            CLog.i(_tag, $"Init()...firstRoleId={CPara.firstRoleId}/{id}...");
            _TestLog("Init()");
            roleAi.Init(this);
            if (CPara.firstRoleId == id) {
                CGameCore.firstRole = this;
                rolePosRing = new CRolePosRing();
                rolePosRing.Init(root);
                currDistanceTips = new CCurrentDistanceTips();
                currDistanceTips.Init();
                maxDistanceTips = new CMaxDistanceTips().Init();
                maxDistanceTips.SetData(CCylinderTerrain.inst.circle.para.centerPoint, CCylinderTerrain.CPara.radius);
                CMaxDistanceTips.CPara.onShowNewRecordTips += currDistanceTips.ShowNewRecordTips;
            }
        }

        float _JetpackSpeed, _JetpackGasDuration, _currJetpackDuration;
        const float roleDefSpeed = 3;

        public void GameReset() {
            CLog.i(_tag, $"GameReset()...firstRoleId={CPara.firstRoleId}/{id}...");
            _TestLog("GameReset()");
            flyCount = 0;
            currFlyDistance = 0;
            _isDeath = false;
            position = rebornPos;
            rootTf.eulerAngles = -Vector3.up * 180;
            subRoot.localPosition = Vector3.zero;
            jetpack.IsShowWing(false);
            jetpack.IsShowEffect(false);

            if (CPara.firstRoleId == id) {
                currDistanceTips.GameReset(id);
                rolePosRing.IsShow(true);
                rolePosRing.SetShow(position, Vector3.up, 0);
                maxDistanceTips.IsShow(id, false);
            }
            trailingGround.IsShow(false, position, Vector3.up);
            PlayAnim(EAnimType.idle);
            currRealPos = position;
            lastDeltaTime = 0.04f;
            isStartCalculationFlyDistance = false;
            roleAi.GameReset();
        }

        float randomSpeed;

        public void GameStart() {
            CLog.i(_tag, $"GameStart()...firstRoleId={CPara.firstRoleId}/{id}...");
            _TestLog("GameStart()");
            randomSpeed = UnityEngine.Random.Range(GlobalTripleJumpCfg.random[0], GlobalTripleJumpCfg.random[1]);
            //randomSpeed = 1;
            //o_JumpSpeedY = Cfg_PlayerProperty.GetConfig((int)parameter.o_playerJumpLevel.Value).o_JumpSpeed;
            int playerJetpackLevel = TripleJumpData.curr.playerJetpackLevel; //.Value;
            _JetpackSpeed = Cfg_PlayerProperty.Get(playerJetpackLevel).JetpackSpeed;
            _JetpackGasDuration = Cfg_PlayerProperty.Get(playerJetpackLevel).JetpackGasDuration;
            _currJetpackDuration = Cfg_PlayerProperty.Get(playerJetpackLevel).JetpackDuration;

            jetpack.SetEnergy(id, _JetpackGasDuration);
            jumpQuality = 0;
            currRealPos = position;
            PlayAnim(EAnimType.turn);
            roleAi.S_GameStart();
            CDelayMain.DelayFrame(0).
                SetPauseEvent(delegate() {
                    return isHelpStep;
                }).
                SetCallGo("", "", CGameState._GameIsEnd).
                onCallback = delegate {
                rootTf.DORotate(Vector3.zero, 1).
                    OnComplete(delegate() {
                        PlayAnim("readyGo");
                        CDelayMain.Delay(1.5f).SetPauseEnd("").onCallback = delegate {
                            PlayAnim(EAnimType.run);
                            //obj.transform.DOLocalMoveZ(obj.transform.localPosition.z+1, 0.3f).SetEase(Ease.InOutBack).OnComplete(delegate () {
                            isRuning = true;
                            accZ = -5;
                            moveSpeedZ = roleDefSpeed;
                            SetFlyState(EFlyState.e07_toGround);
                            _ClickFly(0);
                            // });
                        };
                    });
            };
        }

        public void GameEnd() {
            isRuning = false;
            roleAi.GameEnd();
        }

        /// <summary>
        /// 点击飞行
        /// </summary>
        public void ClickFly() {
            if (isHelpStep) {
                return;
            }
            if (isRuning == false || _isDeath) {
                return;
            }
            if (_flyState == EFlyState.e07_toGround) {
                _ClickFly(Mathf.Abs(fallTimePoint - Time.time));
            } else {
                if (flyCount == 3 && isCanJetpackGas) {
                    jetpack.IsShowEffect(true);
                }
                lastClickTime = Time.time;
                if (CPara.firstRoleId == id) {
                    Debug.LogFormat("点击了___角色没有落地__________");
                }
            }
        }

        float lastClickTime;

        float jumpQuality;
        internal int flyCount;

        void _ClickFly(float clickTimeInterval) {
            flyCount++;
            var cfg2 = Cfg_PlayerProperty.Get(TripleJumpData.curr.playerJumpLevel);
            switch (flyCount) {
                case 1:
                    jumpQuality = _jumpQuality(flyCount, Mathf.Abs(position.z - CPara.startJumpLine), GlobalTripleJumpCfg.accuracy1);
                    // jumpQuality = 1;
                    _maxFlySpeedZ = cfg2.FlySpeed1;
                    var _jumpSpeedY = cfg2.JumpSpeed1;
                    moveSpeedY = _jumpSpeedY * jumpQuality * randomSpeed;
                    moveSpeedZ = moveSpeedY * 2.3f;

                    PlayAnim("flyLeft", 0.8f);
                    break;
                case 2:
                    jumpQuality += _jumpQuality(flyCount, clickTimeInterval, GlobalTripleJumpCfg.accuracy2);
                    // jumpQuality = 2;
                    _maxFlySpeedZ = cfg2.FlySpeed2;
                    _jumpSpeedY = cfg2.JumpSpeed2;

                    moveSpeedY = _jumpSpeedY * (jumpQuality / 2) * randomSpeed;
                    moveSpeedZ = moveSpeedY * 2.3f;
                    PlayAnim("flyRight", 0.8f);
                    break;
                case 3:
                    jumpQuality += _jumpQuality(flyCount, clickTimeInterval, GlobalTripleJumpCfg.accuracy3);
                    //  jumpQuality = 3;
                    _maxFlySpeedZ = cfg2.FlySpeed3;
                    _jumpSpeedY = cfg2.JumpSpeed3;
                    moveSpeedY = (_jumpSpeedY + _JetpackSpeed) * (jumpQuality / 3) * randomSpeed;
                    moveSpeedZ = moveSpeedY * 2.3f;
                    jetpack.IsShowWing(true);
                    jetpack.IsShowEffect(true);
                    if (rolePosRing != null) {
                        rolePosRing.IsShow(false);
                    }
                    isCanJetpackGas = false;
                    JetPackStartMusic = CMusicManage.PlayMusic(MusicCfg.JetPackStart);
                    CDelayMain.Delay(0.5f).SetPauseEnd("").onCallback = delegate {
                        isCanJetpackGas = true;
                        if (CPara.firstRoleId == id) {
                            if (Input.GetMouseButton(0) == false && Input.touchCount == 0) {
                                jetpack?.IsShowEffect(false);
                                JetPackStartMusic?.Stop();
                            }
                        }
                    };
                    PlayAnim("flyLeft", 0.8f);
                    break;
                default:
                    Debug.LogErrorFormat("超级错误_______过分的点击={0}________", flyCount);
                    return;
            }
            const float minAccY = 9.8f;
            float testTime = moveSpeedY / minAccY;
            float testHigh = (minAccY * testTime * testTime) / 2f;

            if (testHigh < para.maxHighLimit) {
                maxHighPointTime = testTime;
                accY = minAccY;
            } else {
                maxHighPointTime = (para.maxHighLimit * 2) / moveSpeedY;
                accY = moveSpeedY / maxHighPointTime;
                // accY = accY < minAccY ? minAccY : accY;
            }
            //accY *= 2;
            accZ = accY * 2.2f;
            currRealPos = position;
            //if (CPara.fristRoleId == id) {
            //CLog.i(_tag, $"开始飞行...firstRoleId={CPara.firstRoleId}/{id}...flyCount={flyCount}/{maxHighPointTime}....._maxFlySpeedZ={_maxFlySpeedZ}/accY={accY}/moveSpeedY={moveSpeedY}/moveSpeedZ={moveSpeedZ}");
            _TestLog("点击..开始飞行");
            SetFlyState(EFlyState.e01_startJump);
            CDefEffectManage.PlayEffect(GlobalTripleJumpCfg.artPath_crashSmokeMini, position);
            lastClickTime = 0;
        }

        void _TestLog(string func) {
            CLog.i(_tag, $"{func}...firstRoleId={CPara.firstRoleId}/{id}...flyCount={flyCount}/{maxHighPointTime}....._maxFlySpeedZ={_maxFlySpeedZ}/accY={accY}/moveSpeedY={moveSpeedY}/moveSpeedZ={moveSpeedZ}");
        }

        CMusicManage.CAudio JetPackStartMusic;
        //距离 = (速度*时间)/2

        /// <summary>
        /// 手指抬起
        /// </summary>
        public void FingerLift() {
            if (flyCount == 3 && isCanJetpackGas) {
                jetpack.IsShowEffect(false);
            }
        }

        bool isCanJetpackGas;
        /// <summary>
        /// 是否落地
        /// </summary>
        public bool IsToGround => _flyState == EFlyState.e07_toGround;

        /// <summary>
        /// 跌落时间点
        /// </summary>
        float fallTimePoint;

        /// <summary>
        /// 是否死亡
        /// </summary>
        public override bool IsDestroyOrDeath() => _isDeath;

        public void SetIsHelpStep(bool isHelpStep) {
            CLog.i(_tag, $"SetIsHelpStep()..设置角色是否能够运行_____________{isRuning}");
            this.isHelpStep = isHelpStep;
            if (flyCount == 3 && isHelpStep == false) {
                jetpack.SetEnergy(id, _JetpackGasDuration);
            }
        }

        bool isHelpStep;
        bool _isDeath { get; set; }
        bool isRuning;

        public override void Update() {
            if (isHelpStep) {
                return;
            }
            base.Update();
            if (isRuning == false) {
                return;
            }
            FlyUpdate();
        }

        float accY = 9.8f;
        float accZ { get; set; }
        float moveSpeedY { get; set; }
        float moveSpeedZ { get; set; }
        float _maxFlySpeedZ { get; set; }

        float maxHighPointTime;
        /// <summary>
        /// 射线没有碰撞到地面的次数
        /// </summary>
        int noHitCount;
        [FormerlySerializedAs("currentFlyDistance")]
        public float currFlyDistance;
        /// <summary>
        /// 是否开始计算飞行距离
        /// </summary>
        bool isStartCalculationFlyDistance;
        /// <summary>
        /// 当前真实位置
        /// </summary>
        Vector3 currRealPos;

        internal EFlyState _flyState { get; set; }
        float lastDeltaTime = 0.04f;
        float totalHigh;
        float deltaTime;

        /// <summary>
        /// 角色运行刷新------------------------------------------------------------------------------
        /// </summary>
        void FlyUpdate() {
            if (_isDeath) {
                return;
            }
            _TestLog("FlyUpdate()......");
            deltaTime = Time.deltaTime;
            deltaTime = Mathf.Lerp(lastDeltaTime, deltaTime, 0.2f);
            lastDeltaTime = deltaTime;
            var downDir = (CCylinderTerrain.inst.circle.para.centerPoint - position); //朝向地形中心方向
            var downDirNormalized = downDir.normalized;
            var forwardDirection = CCylinderTerrain.inst.circle.ToCircleDirection(position, Vector3.forward);
            rotation = Quaternion.FromToRotation(Vector3.up, -downDirNormalized);

            if (isStartCalculationFlyDistance) {
                currFlyDistance += moveSpeedZ * deltaTime;
            } else {
                if (position.z > CPara.startJumpLine) {
                    isStartCalculationFlyDistance = true;
                }
            }

            if (_flyState != EFlyState.e07_toGround) {
                if (_flyState != EFlyState.e04_Peak) {
                    if (moveSpeedY > -moveSpeedZ * 0.5f) { //向下落地是，小于一定的角度将不再，减小向下速度
                        moveSpeedY -= accY * deltaTime;
                    }
                } else if (jetpack.isUse) {
                    _currJetpackDuration += deltaTime;
                }
                if (_flyState == EFlyState.e01_startJump || _flyState == EFlyState.e04_Peak) {
                    if (moveSpeedZ > _maxFlySpeedZ) {
                        moveSpeedZ -= accZ * deltaTime;
                    }
                }
                //角色旋转
                //if (flyCount == 3) {
                //    if (jumpQuality > 0.6f) {
                //        Vector3 up = obj.transform.TransformDirection(0,0.5f,0)+ obj.transform.position;
                //        subRoot.RotateAround(up, Vector3.right,-jumpQuality*3 * deltaTime);
                //    }
                //}else 
                if (flyCount == 4) {
                    var up = rootTf.TransformDirection(0, 0.5f, 0) + position;
                    subRoot.RotateAround(up, Vector3.right, 460 * deltaTime);
                }
                jetpack.SetMotionSpeed((int)(moveSpeedZ + 1));
                if (_flyState == EFlyState.e01_startJump) {
                    if (0 > moveSpeedY) {
                        moveSpeedY = 0;
                        accY *= 0.2f;
                        SetFlyState(EFlyState.e04_Peak);
                        if (flyCount == 3) {
                        } else {
                        }
                    }
                } else if (_flyState == EFlyState.e04_Peak) {
                    if (flyCount == 3) {
                        _currJetpackDuration -= deltaTime;
                        if (_currJetpackDuration < 0) {
                            SetFlyState(EFlyState.e06_downLand);
                            if (CPara.firstRoleId == id) {
                                currDistanceTips.IsShow(true);
                                maxDistanceTips.IsShow(id, true);
                            }
                            PlayAnim("toGround");
                        }
                        //Debug.LogErrorFormat("当前速度______________{0}___{1}", motionSpeedY, motionSpeedZ);
                    } else {
                        SetFlyState(EFlyState.e06_downLand);
                    }
                    //currentHigh0 = currentHigh0> parameter.maxHighLimit? parameter.maxHighLimit : currentHigh0;
                }
                //Vector3 direction = parameter.circle.S_ToCircleDirection(obj.transform.position, new Vector3(0, motionSpeedY, motionSpeedZ * (1 + currentHigh0 / 1000)));
                var direction = CCylinderTerrain.inst.circle.ToCircleDirection(position, new Vector3(0, moveSpeedY, moveSpeedZ));
                currRealPos += direction * deltaTime;

                //喷气背包推进力-----状态关闭
                if (flyCount == 30) {
                    float distance = Vector3.Distance(currRealPos, CCylinderTerrain.inst.circle.para.centerPoint);
                    if (distance > totalHigh) {
                        currRealPos = Vector3.Lerp(CCylinderTerrain.inst.circle.para.centerPoint, currRealPos, totalHigh / distance);
                    } else if (distance > 1) {
                        if (_flyState != EFlyState.e01_startJump) {
                            if (jetpack.isUse) {
                                //喷气背包朝喷气的反方向前进
                                //currentActualPosi += subRoot.up * deltaTime*3;

                                currRealPos -= downDirNormalized * deltaTime * 3;
                            } else {
                                if (distance - CCylinderTerrain.CPara.radius > para.maxHighLimit - 15) {
                                    //高度大于一定值时，自由下降，给喷气背包下降留有一定空间
                                    currRealPos += downDirNormalized * deltaTime;
                                }
                            }
                        }
                    }
                }
                position = currRealPos;

                RaycastHit hit;
                if (Physics.Raycast(position - downDirNormalized * 10, downDirNormalized, out hit, 1800)) {
                    Debug.DrawLine(position, hit.point, Color.red, 1000);
                    if (CPara.firstRoleId == id) {
                        rolePosRing.SetShow(hit.point, hit.normal, hit.distance - 10);
                        currDistanceTips.SetShow(hit.point, hit.normal, currFlyDistance * CPara.distanceRatio);
                        maxDistanceTips.SetShow(hit.point, hit.normal, currFlyDistance, TripleJumpData.curr.maxDistance / CPara.distanceRatio);
                    }
                    noHitCount = 0;
                    bool toGround = false;
                    float clickTimeInterval = 100;
                    if (hit.distance < 10.03f) {
                        toGround = true;
                        fallTimePoint = Time.time;
                    }
                    if (_flyState == EFlyState.e06_downLand && moveSpeedY < -1) {
                        if (hit.distance < 10 - moveSpeedY * deltaTime * 2) {
                            // Debug.LogErrorFormat("抛物线落地_________{0}____{1}________{2}____{3}",flyCount, deltaTime, hit.distance, motionSpeedY);
                            toGround = true;
                            fallTimePoint = Time.time;
                            // Debug.DrawLine(obj.transform.position+Vector3.up*10, hit.point, Color.green, 1000);
                        }
                        if (hit.distance < 200f) {
                            if (flyCount == 1) {
                                if (hit.distance - 10 < GlobalTripleJumpCfg.forwardShake2 * -moveSpeedY) {
                                    if (lastClickTime > Time.time - 0.5f) {
                                        toGround = true;
                                        clickTimeInterval = -(hit.distance - 10) / moveSpeedY;
                                        fallTimePoint = Time.time + clickTimeInterval;
                                    }
                                }
                            } else if (flyCount == 2) {
                                if (hit.distance - 10 < GlobalTripleJumpCfg.forwardShake2 * -moveSpeedY) {
                                    if (lastClickTime > Time.time - 0.5f) {
                                        toGround = true;
                                        clickTimeInterval = -(hit.distance - 10) / moveSpeedY;
                                        fallTimePoint = Time.time + clickTimeInterval;
                                    }
                                }
                            }
                        }
                    }
                    if (toGround) {
                        CMusicManage.PlayMusic(MusicCfg.HitFloor);
                        accZ = moveSpeedZ / 2.5f;
                        switch (flyCount) {
                            case 1:
                                SetFlyState(EFlyState.e07_toGround);
                                if (clickTimeInterval < GlobalTripleJumpCfg.forwardShake2) {
                                    currRealPos = hit.point + hit.normal * 0.2f;
                                    position = currRealPos;
                                    _ClickFly(clickTimeInterval);
                                }
                                break;
                            case 2:
                                SetFlyState(EFlyState.e07_toGround);
                                if (clickTimeInterval < GlobalTripleJumpCfg.forwardShake3) {
                                    currRealPos = hit.point + hit.normal * 0.2f;
                                    position = currRealPos;
                                    _ClickFly(clickTimeInterval);
                                }
                                break;
                            case 3:
                                jetpack.IsShowEffect(false);
                                if (CPara.firstRoleId == id) {
                                    currDistanceTips.IsShow(true);
                                }
                                float[] random = GlobalTripleJumpCfg.jump04_Random;
                                downLandRandom = UnityEngine.Random.Range(random[0], random[1]);
                                float[] jump04Value = GlobalTripleJumpCfg.jump04_value;
                                float speedZMax = jump04Value[0];
                                if (moveSpeedZ < speedZMax) {
                                    moveSpeedZ = moveSpeedZ * jump04Value[2];
                                } else {
                                    moveSpeedZ = speedZMax * jump04Value[2];
                                }
                                moveSpeedY = speedZMax * jump04Value[1];

                                SetFlyState(EFlyState.e01_startJump);
                                flyCount = 4;
                                accZ = 0;
                                accY = 6.8f;
                                currRealPos = hit.point + hit.normal * 0.2f;
                                //obj.PlayAnim("flyRight", 0.5f);
                                PlayAnim("squat");
                                //C_ObjBase.mono.S_Delayed(0.8f).d_EndEvent = delegate () {
                                //     PlayAnim("FlyRight", 0.5f);
                                //};
                                _jumpQuality(flyCount, 10, GlobalTripleJumpCfg.accuracy3);
                                maxHighPointTime = 0.5f;
                                //jumpMaxHighPointTime = maxHighPointTime0 + Time.time;
                                subRoot.localEulerAngles = Vector3.zero;
                                subRoot.localPosition = Vector3.zero;
                                CMusicManage.PlayMusic(MusicCfg.jump);
                                CVibrator.OpenVibrator(0, 100);
                                break;
                            case 4:
                                SetFlyState(EFlyState.e07_toGround);
                                trailingGround.IsShow(true, hit.point, hit.normal);
                                #if xxx
                                 PlayAnim(EAnimType.die);
                                #else
                                PlayAnim(EAnimType.run);
                                #endif
                                subRoot.localEulerAngles = Vector3.zero;
                                subRoot.localPosition = Vector3.zero;
                                accZ = (moveSpeedZ / 2.5f) * (1 + downLandRandom);
                                break;
                            default: return;
                        }
                    }
                } else {
                    noHitCount++;
                    CLog.Ee(_tag, $"超级严重的错误______00_______找不到飞行地面______{noHitCount}_____{name}");
                    //rootTf.Translate(new Vector3(0, motionSpeedY, motionSpeedZ) * deltaTime);
                    this.Translate(new Vector3(0, moveSpeedY, moveSpeedZ) * deltaTime);
                    if (noHitCount > 6) {
                        CPara.onRoleDeath(id, flyCount, Mathf.RoundToInt(currFlyDistance * CPara.distanceRatio));
                    }
                }
                return;
            } else {
                //Debug.LogErrorFormat("奔跑__________ flyCount={0}", flyCount);
                moveSpeedZ -= accZ * deltaTime;
                RaycastHit hit;
                if (Physics.Raycast(position - downDirNormalized * 10, downDirNormalized, out hit, 1800)) {
                    if (rolePosRing != null) {
                        rolePosRing.SetShow(hit.point, hit.normal, 0);
                    }
                    Vector3 direction = CCylinderTerrain.inst.circle.ToCircleDirection(position, new Vector3(0, 0, moveSpeedZ));
                    position = hit.point + direction * deltaTime;
                    if (CPara.firstRoleId == id) {
                        currDistanceTips.SetShow(hit.point, hit.normal, currFlyDistance * CPara.distanceRatio);
                        maxDistanceTips.SetShow(hit.point, hit.normal, currFlyDistance, TripleJumpData.curr.maxDistance / CPara.distanceRatio);
                    }
                    if (flyCount == 0) {
                        if (CPara.startJumpLine < position.z && accZ <= 0) {
                            accZ = moveSpeedZ * 1.5f;
                            // fallTime = Time.time;
                        }
                    }
                    if (flyCount == 4) {
                        #if xxx
                        if (motionSpeedZ < 0.05f) {
                            _isDeath = true;
                        }
                        #else
                        if (moveSpeedZ < 0.95f) {
                            _isDeath = true;
                        }
                        #endif
                    } else {
                        if (moveSpeedZ < 0.65f) {
                            _isDeath = true;
                        }
                    }
                    if (_isDeath) {
                        #if xxx
                         PlayAnim(EAnimType.die);
                        #else
                        if (flyCount == 4) {
                            PlayAnim(EAnimType.idle, 1);
                        } else {
                            PlayAnim(EAnimType.die);
                        }
                        #endif
                        CPara.onRoleDeath(id, flyCount, Mathf.RoundToInt(currFlyDistance * CPara.distanceRatio));
                        if (flyCount != 4) {
                            CMusicManage.PlayMusic(MusicCfg.HitFloor);
                            CVibrator.OpenVibrator(0, 70);
                        }
                    }
                    if (flyCount == 4) {
                        trailingGround.S_SetShow(hit.point, hit.normal);
                        #if !xxx
                        if (!_isDeath) {
                            float speed = moveSpeedZ / (roleDefSpeed);
                            //Debug.LogErrorFormat("奔跑角色_________________{0}_____{1}", speed, motionSpeedZ);
                            PlayAnim(EAnimType.run, speed);
                        }
                        #endif
                    }
                } else {
                    noHitCount++;
                    CLog.Ee(_tag, $"超级严重的错误_____11________找不到飞行地面______{noHitCount}_____{name}");
                    //rootTf.Translate(new Vector3(0, motionSpeedY, motionSpeedZ) * deltaTime);
                    this.Translate(new Vector3(0, moveSpeedY, moveSpeedZ) * deltaTime);
                    if (noHitCount > 6) {
                        CPara.onRoleDeath(id, flyCount, Mathf.RoundToInt(currFlyDistance * CPara.distanceRatio));
                    }
                }
                if (flyCount == 0 && nextRunMusicTime < Time.time) {
                    nextRunMusicTime = Time.time + 0.2f;
                    isLeftFootMusic = !isLeftFootMusic;
                    if (isLeftFootMusic) {
                        CMusicManage.PlayMusic(MusicCfg.LeftFootStep);
                    } else {
                        CMusicManage.PlayMusic(MusicCfg.RightFootStep);
                    }
                }
            }
        }

        bool isLeftFootMusic;
        float nextRunMusicTime;
        float downLandRandom = 0.5f;

        float _jumpQuality(int flyCount, float intervalTime, float[][] accArrArr) {
            int accIndex = accArrArr[1].Length - 1;
            for (int i = 0; i < accArrArr[0].Length; i++) {
                if (intervalTime < accArrArr[0][i]) {
                    accIndex = i;
                    break;
                }
            }
            //if (C_Parameter.o_fristRoleId == id) {
            CPara.onJumpQuality(id, flyCount, accIndex);
            //}
            return accArrArr[1][accIndex];
        }

        void SetFlyState(EFlyState flyState) {
            CLog.i(_tag, $"设置飞行阶段........{flyState}");
            _flyState = flyState;
            CPara.onSetFlyState(id, flyCount, flyState, maxHighPointTime);
        }

        public class CPara {
            public static float startJumpLine = -70;

            /// <summary>
            /// 角色id，跳起阶段,跳的质量,
            /// </summary>
            public static Action<int, int, int> onJumpQuality;
            /// <summary>
            /// 角色id，跳起阶段,飞行阶段,到达最高点的时间
            /// </summary>
            public static Action<int, int, EFlyState, float> onSetFlyState;
            public const float roleStartPosZ = -90;
            /// <summary>
            /// 角色id，跳起阶段,最远距离
            /// </summary>
            public static Action<int, int, int> onRoleDeath;

            /// <summary>
            /// 场景缩放距离比例尺
            /// </summary>
            public const float distanceRatio = 1.54f;

            public float maxHighLimit = 250;
            public static int firstRoleId;

            public string playerName;
            public Color playerNameColor;
            public Color playerNameBackColor;
        }
        /// <summary>
        /// 飞行状态
        /// </summary>
        public enum EFlyState {
            /// <summary>
            /// 开始跳
            /// </summary>
            e01_startJump = 1,
            /// <summary>
            /// 最高点
            /// </summary>
            e04_Peak = 4,
            /// <summary>
            /// 下落高度限制1
            /// </summary>
            e06_downLand = 6,
            /// <summary>
            /// 落地
            /// </summary>
            e07_toGround = 7,
        }
    }
}
